<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<title>注册页</title>
	<link rel="stylesheet" href="../css/reset.css">
	<style>
		body{
			background-image: url(../images/login_bg.jpg);
			background-size: 100% 100%;
			overflow: hidden;
		}
		.wrap{
			width: 500px;
			height: 200px;
			margin: 200px;
			display: flex;
			justify-content: center;
			flex-direction: column;
		}
		.wrap span{
			display: inline-block;
			width: 100px;
			color: #fff;
			text-align: right;
			margin-right: 5px;
			font-size: 20px;
		}
		input{
			width: 250px;
			height: 35px;
			padding-left: 10px;
		}
		.wrap div{
			margin-top: 15px;
		}
		.btn{
			display: flex;
			justify-content: center;
		}
		.btn button{
			width: 100px;
			height: 35px;
			border-radius: 4px;
			cursor: pointer;
		}
	</style>
</head>
<body>
	<!-- 注册页 -->
	 <div class="wrap">
		<div>
			<span>手机</span>
			<input type="text" placeholder="请输入手机号" class="phone">
		</div>
		<div>
			<span>密码</span>
			<input type="password" class="pws">
		</div>
		<div>
			<span>确认密码</span>
			<input type="password" class="pwss">
		</div>
		<div class="btn">
			<button onclick="submitData()">提交</button>
		</div>
	 </div>
	 <script src="../../public1/js/sweetalert.js"></script>
	 <script src="../../public1/js/pubilc.js"></script>
	 <script src="../../public1/js/md5.js"></script>
	 <script>
		 var phone = document.querySelector('.phone')
		 var pws = document.querySelector('.pws')
		 var pwss = document.querySelector('.pwss')
		 var phoneReg =  /^1[34578]\d{9}$/
		var pass = /^(\w){6}$/;
		 function submitData(){
			if(!phoneReg.test(phone.value)){
				popupMsg('error','手机格式不正确')
				return
			}
			if(!pass.test(pws.value)){
				popupMsg('error','六位数密码不规范')
				return
			}
			if(pws.value===pwss.value){
				xhr({
					url:"/user/register",
					methods:'post',
					data:JSON.stringify({
						userPhone:phone.value,
						password:md5(pws.value),
						rolu:2
					}),
					success:function(res){
						swal({
							title:'注册成功,直接登录?',
							buttons: ["取消", "确定"],
						}).then(res=>{
							if(res){
								xhr({
									methods:'post',
									url:'/user/getLogin',
									data:JSON.stringify({
										userPhone:phone.value,
										password:md5(pws.value),
										rolu:2
									}),
									success:function(res){
										location.replace('./home.html?token='+res.data.token+"&user="+phone.value)
									}
								})
							}
						})
					}
				})
			}else{
				popupMsg('error','密码输入不一致')
			}
		 }
	 </script>
</body>
</html>